#include <bits/stdc++.h>

using namespace std;

int t, n, m, L, V;
int d[3005], v[3005], a[3005];
int p[3005];
bool vis[3005];

int qpow (int x, int y){
	int res = 1, ans = x;
	while (y){
		if (y & 1)
			res *= ans;
		ans *= ans;
		y >>= 1;
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	freopen ("detect.in", "r", stdin);
	freopen ("detect.out", "w", stdout);
	cin >> t;
	while (t--){
		int ans = 0, res = 0;
		cin >> n >> m >> L >> V;
		for (int i = 1; i <= n; i++){
			cin >> d[i] >> v[i] >> a[i];
			if (a[i] < 0 && v[i] > V && d[i] <= lst)
				cnt++;
		}
		int lst = 0;
		for (int i = 1; i <= m; i++){
			cin >> p[i];
			lst = max (lst, p[i]);
		}
			int psmx = 0, psmn = INT_MAX;
			int ps1mx = 0, ps1mn = INT_MAX;
			for (int i = 1; i <= n; i++){
				if (a[i] == 0){
					if (v[i] > V && d[i] <= lst){
						ans++;
						int pos = lower_bound (p + 1, p + m + 1, d[i]);
						vis[pos] = true;
						continue;
					}
				}
				if ((qpow (V, 2) - qpow (v[i], 2)) / (2 * a[i]) + d[i] <= lst && a[i] > 0){
					int pos = lower_bound (p + 1, p + m + 1, (qpow (V, 2) - qpow (v[i], 2)) / (2 * a[i]) + d[i]);
					ans++;
				}
				else if (a[i] < 0 && v[i] > V && d[i] <= lst){
					int pos = lower_bound (p + 1, p + m + 1, (qpow (V, 2) - qpow (v[i], 2)) / (2 * a[i]) + d[i]);
					if (p[pos] > (qpow (V, 2) - qpow (v[i], 2)) / (2 * a[i]) + d[i])
						pos--;
					int pos1 = lower_bound (p + 1, p + m + 1, d[i]);
					if (pos - pos1 > 1 || p[pos1] == d[i] || p[pos] <= (double)(qpow (V, 2) - qpow (v[i], 2)) / (2 * a[i]) + d[i]){
						ans++;
						psmx = max (pos, psmx), psmn = min (pos, psmn);
						ps1mx = max (pos1, ps1mx), ps1mn = min (pos, ps1mn);
					}
				}
			}
			if (cnt)
				res = n - 2;
			cout << ans << ' ' << res << '\n';
			continue;
	}
	return 0;
}
